/*
 * driver: uart
 * File: $Id: uartcallback.c
 *
 *  Created on: 2019年1月4日
 *      Author: hongwei
 */

#include "uartcallback.h"
#include "udp_comm.h"
#include "fpga_nand.h"

//__weak void uart1_rxcallback(uint8_t *rxdate, uint16_t len)
//{
//	printf("uart1 :%d is:%s\r\n", len, rxdate);
//}

__weak void uart2_rxcallback(uint8_t *rxdate, uint16_t len)
{
	printf("uart2 :%d is:%s\r\n", len, rxdate);
}

__weak void uart3_rxcallback(uint8_t *rxdate, uint16_t len)
{
	printf("uart3 :%d is:%s\r\n", len, rxdate);
}


void uart1_rxcallback(uint8_t *rxdate, uint16_t len)
{
    uint8_t  Reg8Value[4];
    uint16_t crc_init = 0, carAdd, crc_rcv;
    uint32_t RegValue;
    if(0xaa == rxdate[0])
    {
        switch (rxdate[1])
        {
            case 1:
                SMI_read_PHY(rxdate[2], rxdate[3], &RegValue);
                printf("uart1 read %d  %d %0x\r\n",rxdate[2],rxdate[3],RegValue);
                //HAL_NAND_Read_Page_8b(&hnand1, NAND_AddressTypeDef *pAddress, uint8_t *pBuffer, uint32_t NumPageToRead);
                break;

            case 2:
                printf("uart1 cmd %d\r\n",rxdate[2]);
                udp_EXTI_IdleCallback(rxdate[2], rxdate[3]);
                break;
            case 3:
                printf("UDP rcv speed = %d kbps!, losCnt = %d rcvCnt = %d\n", udp_getPara(3)*8/20000,udp_getPara(1), udp_getPara(2));
                break;
            case 4: //
                Reg8Value[0] = fpga_One_read(rxdate[2]);
                printf("FPGA read add:%d  data = %d\n", rxdate[2], Reg8Value[0]);
                break;
            case 5: //
                printf("FPGA write add:%d  data = %d\n", rxdate[2], rxdate[3]);
                fpga_One_write(rxdate[2], rxdate[3]);
                break;

            case 6: //
                fpga_read(rxdate[2], Reg8Value, 4);
                printf("FPGA read add:%d  data = %0x  %0x  %0x  %0x\n", rxdate[2], Reg8Value[0], Reg8Value[1], Reg8Value[2], Reg8Value[3]);
                break;
            case 7: //
                Reg8Value[0] = rxdate[2];Reg8Value[1] = rxdate[2]+1;Reg8Value[2] = rxdate[2]+2;Reg8Value[3] = rxdate[2]+3;
                fpga_write(rxdate[2],Reg8Value, 4);
                printf("FPGA write add:%d\n", rxdate[2]);
                break;
            default:
                break;
        }
    }
}
